<template>
  <el-dialog title="建档率统计结果明细" :visible.sync="visible" :close-on-click-modal='false' fullscreen center append-to-body>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-button type="primary" class="miui-dialog-print-btn" @click="exportHandle" :loading="isExport">导出</el-button>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="index" label="序号" width="50"></el-table-column>
      <el-table-column prop="certificateNum" label="身份证号" width="160"></el-table-column>
      <el-table-column prop="studentName" label="姓名" width="160"></el-table-column>
      <el-table-column prop="birthDay" label="出生年月" width="120"></el-table-column>
      <el-table-column prop="gender" label="性别" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.gender == '0'">男</span>
          <span v-if="scope.row.gender == '1'">女</span>
        </template>
      </el-table-column>
      <el-table-column prop="fullName" label="学校" min-width="160"></el-table-column>
      <el-table-column prop="telPhone" label="联系方式" width="160"></el-table-column>
    </el-table>

  </el-dialog>
</template>

<script>
  import { remote } from '@/api/admin/dict'
  import { getCheckDetailExport } from '@/api/pvm/filingRate'
  import { getDetailByAllStudent, getDetailByCheckNot, getDetailByOptoNot } from '@/api/pvm/filingRate'

  export default {
    data() {
      return {
        visible: false,
        isExport: false,
        params: {},
        tableData: []
      }
    },
    components: {},
    methods: {
      init(params,type) {
        /* type
          近视监测(should应到人数 checkActual-实到人数 checkNot-未到人数)
          屈光档案(should应到人数 optoActual-实到人数 optoNot-未到人数)
        */
        this.visible = true;
        //  获取年级信息
        this.$nextTick(() => {
          this.getDetail(params,type)
        })
      },
      getDetail(data,type){
        switch(type){
          case 'should':
            data.exportFlag = 3
            getDetailByAllStudent(data).then(response => {
              if(response.data.code == '0'){
                this.tableData = response.data.data
              }else{
                this.$message.error(response.data.mdg)
              }
            })
            break;
          case 'checkActual':
            data.lackFlag = 1
            data.exportFlag = 1
            getDetailByCheckNot(data).then(response => {
              if(response.data.code == '0'){
                this.tableData = response.data.data
              }else{
                this.$message.error(response.data.mdg)
              }
            })
            break;
          case 'checkNot':
            data.lackFlag = 2
            data.exportFlag = 1
            getDetailByCheckNot(data).then(response => {
              if(response.data.code == '0'){
                this.tableData = response.data.data
              }else{
                this.$message.error(response.data.mdg)
              }
            })
            break;
          case 'optoActual':
            data.lackFlag = 1
            data.exportFlag = 2
            getDetailByOptoNot(data).then(response => {
              if(response.data.code == '0'){
                this.tableData = response.data.data
              }else{
                this.$message.error(response.data.mdg)
              }
            })
            break;
          case 'optoNot':
            data.lackFlag = 2
            data.exportFlag = 2
            getDetailByOptoNot(data).then(response => {
              if(response.data.code == '0'){
                this.tableData = response.data.data
              }else{
                this.$message.error(response.data.mdg)
              }
            })
            break;
        }
        this.params = data
      },
      // 导出
      exportHandle() {
        this.isExport = true
        getCheckDetailExport(this.params).then(response => {
            this.isExport = false
            var blob = new Blob([response.data], {
              type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
            });
            var reader = new FileReader();
            reader.readAsDataURL(blob);
            reader.onload = function(e) {
              var a = document.createElement('a');
              a.download = "建档率统计结果明细.xlsx";
              a.href = URL.createObjectURL(blob);
              a.click();
            }
            this.$message.success("导出成功")
        }).catch(() => {
          this.isExport = false
        })
      },




    }
  }
</script>
